﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KYJControlLib
{
    [DefaultEvent("PumpDoubleClick")]
    public partial class Pump : UserControl
    {
        public Pump()
        {
            InitializeComponent();

            //设置控件样式
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, false);
            this.SetStyle(ControlStyles.Selectable, true);
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        }

        private byte pumpState=0;
        [Browsable(true)]
        [Category("自定义属性")]
        [Description("循环泵状态，0:停止;1:运行;2:故障;其他:备用")]
        public byte PumpState
        {
            get { return pumpState; }
            set { pumpState = value;
                switch (pumpState)
                {
                    case 0:this.MainPic.Image = Properties.Resources.PumpStop;break;
                    case 1: this.MainPic.Image = Properties.Resources.PumpRun; break;
                    case 2: this.MainPic.Image = Properties.Resources.PumpFault; break;
                    default: this.MainPic.Image = Properties.Resources.PumpSpare; break;
                }
            }
        }

        [Browsable(true)]
        [Category("自定义属性")]
        [Description("绑定的变量名称")]
        public string BindVarName { get; set; }

        [Browsable(true)]
        [Category("自定义属性")]
        [Description("循环泵序列号")]
        public int PumpIndex { get; set; } = 1;


        [Browsable(true)]
        [Category("自定义事件")]
        [Description("循环泵双击事件")]
        public event EventHandler PumpDoubleClick;

        /// <summary>
        /// 循环泵双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainPic_DoubleClick(object sender, EventArgs e)
        {
            if(PumpDoubleClick != null)
            {
                PumpDoubleClick.Invoke(this, e);
            }
        }
    }
}
